<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>完善当当购物车页面</title>
    <link type="text/css" rel="stylesheet" href="css/cartStyle.css" />
    <script type="text/javascript">
    	function alter1(num){
    		var prices=document.getElementsByName("price")[num].value;
    		var count=parseInt(document.getElementsByName("amount")[num].value)-1;
    		if(count<1){
    			alert("不能再减了，再减就没有啦！")
    		}else{
    			document.getElementsByName("amount")[num].value=count;
    			var totals=parseFloat(prices*count);
    			document.getElementById("price"+num).innerHTML="¥"+totals;
    		}
    	}
    	function alter(num){
    		var prices=document.getElementsByName("price")[num].value;
    		var count=parseInt(document.getElementsByName("amount")[num].value)+1;
    		if(count<1){
    			alert("不能再减了，再减就没有啦！")
    		}else{
    			document.getElementsByName("amount")[num].value=count;
    			var totals=parseFloat(prices*count);
    			document.getElementById("price"+num).innerHTML="¥"+totals;
    		}
    	}
	function total(){
		var prices=document.getElementsByName("price");
		var count=document.getElementsByName("amount");
		var sum=0;
		for(var i=0;i<prices.length;i++){
			sum+=prices[i].value*count[i].value;
		}
		document.getElementById("totalPrice").innerHTML="¥"+sum;
	}
</script>
</head>
<body onload="total()">

<div class="content">
    <div class="logo">
        <img src="images/dd_logo.jpg"><span>关闭</span>
    </div>
    <div class="cartList">
        <ul>
            <li>¥<input type="text" name="price" value="21.90"></li>
            <li><input type="button" name="minus" value="-" onclick="alter1(0),total()"><input type="text" name="amount" value="1"><input onclick="alter(0),total()" type="button" name="plus" value="+"></li>
            <li id="price0">¥21.90</li>
            <li><p>移入收藏</p><p>删除</p></li>
        </ul>
        <ul>
            <li>¥<input type="text" name="price" value="24.00"></li>
            <li><input type="button" name="minus" value="-" onclick="alter1(1),total()"><input type="text" name="amount" value="1"><input type="button" name="plus" value="+" onclick="alter(1),total()"></li>
            <li id="price1">¥24.00</li>
            <li><p>移入收藏</p><p>删除</p></li>
        </ul>
        <ol>
            <li id="totalPrice">&nbsp;</li>
            <li><span>结 算</span></li>
        </ol>
    </div>
</div>
</body>
</html>